/**
 * author      : dormi330
 * date        : 2018/6/24
 * project     : mybatis
 * description : 交易订单实体
 * <p>
 * 一个订单包含多条 item, 但是一次支付
 * 物流可以包含多个
 */

package com.deep.trade.infrastructure.mybatis.cart;

import com.deep.trade.domain.cart.CartRepository;
import com.deep.trade.domain.cart.CartSku;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class MybatisCartRepository implements CartRepository {

    @Autowired
    private CartSkuMapper cartSkuMapper;

    public int skuAddToCart(CartSku cartSku) {
        return cartSkuMapper.insert(cartSku);
    }

    public int cartSkuQuantityChanged(CartSku cartSku) {
        return cartSkuMapper.updateQty(
                // condition
                cartSku.getTenantCode(),
                cartSku.getId(),
                cartSku.getVersion(),

                // changed field
                cartSku.getQuantity(),
                cartSku.getMemberId()
        );
    }


    public int removeCartSku(CartSku cartSku) {
        return cartSkuMapper.removeCartSku(
                cartSku.getTenantCode(),
                cartSku.getId(),
                cartSku.getVersion(),

                cartSku.getMemberId()
        );
    }
}
